<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.layui-table-cell{padding:1px 2px;font-size:13px;}
th .layui-table-cell{line-height:19px;padding:2px 8px;}
.layui-table-view .layui-table td, .layui-table-view .layui-table th{padding:1px 0px;}
th span{white-space:normal;}
.finance tbody tr td {
    padding: 3px 0px !important;
    font-size: 12px !important;
}
.lay-pic {
    max-height: 50px;
}
.notprofit{color:red;}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">订单号</label>
			<div class="layui-input-inline">
				<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">SKU</label>
			<div class="layui-input-inline">
				<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">所属工厂</label>
			<div class="layui-input-inline">
				{:Form::select('factory_id', '', $factoryKV, '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">订单状态</label>
			<div class="layui-input-inline">
				{:Form::select('order_status', '', ['' => '请选择', 1=>'未采购', 2=>'已采购', 3=>'已裁床', 4=>'已车缝', 5=>'已后整', 6=>'已出货', 7=>'已完成'], '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">下单日期</label>
			<div class="layui-input-inline">
				<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">完成日期</label>
			<div class="layui-input-inline">
				<input type="text" name="over_date_range" readonly="" id="over_date_range" lay-verify="" placeholder="选择完成日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">裁床日期</label>
			<div class="layui-input-inline">
				<input type="text" name="caichuang_over_date_range" readonly="" id="caichuang_over_date_range" lay-verify="" placeholder="选择裁床完成日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>
		</div>
	</div>
	</form>
</div>
<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}
<script type="text/html" id="caichuangTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.caichuang_over_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.caichuang_over_time * 1000,'MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="clientStatusTpl">
    {{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span><br> {{# } }}
	{{ clientStatus[d.client_status].replace(/生产中/, "") }}
	<br />环节3天
</script>
<script type="text/html" id="createTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.create_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.create_time * 1000,'yyyy-MM-dd') }} </span>
{{# } }}
{{# if(d.shipment_time > 0){ }} 
	<br/>
	<span title="{{ layui.util.toDateString(d.shipment_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.shipment_time * 1000,'yyyy-MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="timeendTpl">
10天
	<br/>12天
</script>


<script type="text/javascript">
	var factoryKV = {:json_encode($factoryKV);};
	var groupKV = {:json_encode($groupKV);};
	var clientStatus = {:json_encode($clientStatus);};
	groupKV['0'] = '请选择';
	
	layui.use([ 'opTable', 'jquery', 'tool', 'laydate', 'laytpl', 'form'], function() {
		var $ = layui.jquery;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var laydate = layui.laydate;
		
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#over_date_range').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#caichuang_over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#caichuang_over_date_range').val(value);
            	$('#layui-laydate3').remove();//关闭面板
            }
		});
		var opTable = layui.opTable.render({
			elem : '#dataTable'
			,url : '{:url()}'
			,page: true
			,limit: 50
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
			,openVisible: false
			,toolbar: false
	        ,defaultToolbar: ['filter', 'exports', 'print']
			//客户名称	下单期	交货期	订单号	数量	颜色	面料采购期	里料采购期	辅料采购期	批色期	验布期	缩水期	补料原因	裁剪期	裁剪滞后原因	印/绣花期	发料期	异常问题处理
			,cols : [[ 
				{field: 'pic', title:'图片',templet:function(d){return '<span class="lay-pic-container" src="'+ d.pic +'"><img src="'+ d.pic +'" class="lay-pic"></span>'},width:100}
				,{field: 'client_ordernum', title:'订单号/工厂',width:95,templet:function(d){ return'<span class="copy-item">'+d.client_ordernum+'</span>'+"<br>"+d.factory_name;}}
				,{field: 'field0', title:'下单数量',templet: function(d){return  d.osStat.order_count;},width:70}
				,{field: 'createTime', title:'下单期/交货期',width:140,templet:"#createTimeTpl"}
				,{field: 'custom_material_cost', title:'货期时长/剩余',templet:'#timeendTpl'}
				,{field: 'mes_factory', title:'进度节点',templet:'#clientStatusTpl',width:95}
				,{field: 'field0', title:'环节停留/预期/超期'}
				,{field: 'field0', title:'延期概率'}
				,{field: 'field0', title:'面料/里料采购期'}
				,{field: 'material_cost_little', title:'辅料采购期'}
				,{field: 'material_cost_little', title:'批色期'}
				,{field: 'material_cost_little', title:'验布期'}
				,{field: 'material_cost_little', title:'缩水期'}
				,{field: 'material_cost_little', title:'异常环节(退补检色)'}
				,{field: 'material_cost_little', title:'裁剪期'}
				,{field: 'material_cost_little', title:'发料期'}
				,{field: 'material_cost_little', title:'车缝期'}
				,{field: 'material_cost_little', title:'尾整期'}
				,{field: 'material_cost_little', title:'订单跟踪备注'}
			]]
		});	

		form.on('submit(stock-out-in)', function (data) {
			console.log(data.field);
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#stockOutInTpl form')[0].reset();
	 				 layer.close(layerStockOutIn);
					 layer.msg(res.msg, {icon: 1,end:function(){opTable.reload();}});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			
			return false;
		});

	});
</script>